<template>
	<view class="all">
		<view class="usermsg">
			<view class="phone" @click="toPhone()">
				<view class="left">
					手机号
				</view>
				<view class="right iconfont">
					已绑定&nbsp;&nbsp; &#xe60d;
				</view>
			</view>
			<view class="wx" @click="binding()">
				<view class="left">
					微信
				</view>
				<view class="right iconfont"  v-if="!wxStatus">
					未绑定&nbsp;&nbsp; &#xe60d;
				</view>
				<view class="right iconfont" v-else>
					已绑定&nbsp;&nbsp; &#xe60d;
				</view>
			</view>
			<view class="zfb" @click="zfb()">
				<view class="left">
					支付宝
				</view>
				<view class="right iconfont">
					未绑定&nbsp;&nbsp; &#xe60d;
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token:'',
				wxData:{},
				wxStatus:''
			};
		},
		onShow() {
			try {
				const value = uni.getStorageSync('user');
				if (value) {
					this.token = value.api_token
					this.wxStatus=value.wx_status
				}
			} catch (e) {
				// error
			}
		},
		methods:{
			toPhone(){
				uni.navigateTo({
					url:'/pages/my/setting/binding/phoneDetial'
				})
			},
			getApploginData(data){
			var that =this
			let token=that.token
				uni.request({
					url: "https://api.weixin.qq.com/sns/userinfo?access_token="+data.authResult.access_token+"&openid="+data.authResult.openid,
					method: 'GET',
					dataType: 'json',
					header: {
						'content-type': 'application/x-www-form-urlencoded' // 默认值
					},
					
					success(res) {
							if(res.statusCode==200){
								console.log('【登录回调啾啾啾】',res.data,'0000000000000')
								that.wxData=res.data
								uni.request({
									url: "https://www.ghhlkj.com/api/wechatAuthorization",
									method: 'POST',
									header: {
										'Authorization': 'Bearer' + token
									},
									data:that.wxData,
									success(res){
										if(res.data.meta.status==200){
											uni.showToast({ title:'授权成功', icon: 'none' });
										}
									}
								})
							}
						},
					fail() {
						
						}
					})
				},
			binding(){
				var that =this
				uni.getProvider({
				    service: 'oauth',
				    success: function(res) {
				        //支持微信、qq和微博等
				        if (~res.provider.indexOf('weixin')) {
				            uni.login({
				              provider: 'weixin',
				              success: function (loginRes) {
								console.log("App微信获取用户信息成功",loginRes);
				                that.getApploginData(loginRes)  //请求登录接口方法
				              },
				              fail:function(res){
				              console.log("App微信获取用户信息失败",res);
				              }
				            })
				        }
				    }
				});
				
			},
			zfb(){
				
			}
		}
	}
</script>

<style lang="scss" scoped>
.all{
		background-color: #f6f6f6;
		padding-top:5px ;
		.usermsg{
			background-color: #ffffff;
			.phone,.wx,.zfb{
				padding: 0 10px;
				font-size: 16px;
				height: 55px;
				line-height: 55px;
				font-weight: Medium;
				display: flex;
				justify-content: space-between;
				border-bottom: 0.5px  #f6f6f6 solid;
				.right{
					color: #868686;
					font-size: 28rpx;
				}
			}
		}
		}
</style>
